export const tyAddUpdateMixins = {
    data() {
        return {
            drawerFlag: false,
            deleteNameList:null,
        }
    },
    methods: {
        openDrawer(willData) {
            if (willData != null) {
                var currentData = null
                this.$children.forEach(o => {
                    if (o.$vnode.tag.indexOf("tyAddUpdate") != -1) {
                        currentData = o.model
                    }
                })
                this.updateData(currentData, willData)
            }
            this.drawerFlag = true
        },
        updateData(currentData, willData) {
            let obj = this.$data
            for (let o in obj) {
                if (obj[o] == currentData) {
                    obj[o] = JSON.parse(JSON.stringify(willData))
                }
            }
        },
        closeDialogPage(){
            this.drawerFlag = false
        },
        refreshData() {
            this.$refs.tyTable.refreshData()
        },
    },
    mounted() {

    }
}
export const tyConfirmMixins = {
    methods : {
        confirmFn(title, data, api, successMsg , refreshData) {
            this.$confirm(title, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                api(data).then(res=>{
                    this.$message({
                        type: 'success',
                        message: successMsg
                    });
                    refreshData()
                })
            }).catch(()=>{})
        },
        deleteCommon(item, api , refreshData){
            let data = {}
            this.deleteNameList.forEach(val=>{
                data[val] = item[val]
            })
            this.confirmFn('此操作将永久删除该记录, 是否继续?', data, api, '删除成功',refreshData)
        }
    }
}
